// 修改密码
<template>
  <el-dialog title="修改密码" :visible.sync="changePassWord" width="30%" center :show-close="false">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
      size="mini"
    >
      <el-form-item label="用户账号" prop="user">
        <el-input v-model="ruleForm.user" disabled></el-input>
      </el-form-item>
      <el-form-item label="旧的密码" prop="oldPassword">
        <el-input v-model="ruleForm.oldPassword"></el-input>
      </el-form-item>
      <el-form-item label="新的密码" prop="newPassword">
        <el-input v-model="ruleForm.newPassword"></el-input>
      </el-form-item>
      <el-form-item label="重复密码" prop="repeatPassword">
        <el-input v-model="ruleForm.repeatPassword"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')" size="mini">保存数据</el-button>
        <el-button @click="cancel" size="mini">取消编辑</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      ruleForm: {
        user: 'admin',
        oldPassword: '',
        newPassword: '',
        repeatPassword: ''
      },
      rules: {
        user: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        oldPassword: [
          { required: true, message: '请输入旧密码', trigger: 'blur' },
          { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
        ],
        newPassword: [
          { required: true, message: '请输入新密码', trigger: 'blur' },
          { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
        ],
        repeatPassword: [
          { required: true, message: '请输入重复密码', trigger: 'blur' },
          { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$store.commit('myCommon/changePassWord', false)
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false;
        }
      })
    },

    // 取消编辑
    cancel() {
      this.$store.commit('myCommon/changePassWord', false)
    }
  },
  computed: {
    ...mapState('myCommon', ['changePassWord'])
  }
}

</script>

<style lang='scss' scoped>
div {
  .el-row {
    /deep/ .el-dialog__wrapper {
      .el-dialog {
        .el-dialog__header {
          .el-dialog__title{
            color: aqua !important;
          }
        }
      }
    }
  }
}
</style>